package com.lemon.smartsafety.ui.adapter.safe.data;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.entity.event.contract.KeepEditEvent;
import com.lemon.smartsafety.entity.safe.contract.KeepContractVo;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class KeepContractAdapter extends LemonRcvAdapter<KeepContractVo> {
    public KeepContractAdapter(@Nullable List<KeepContractVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new KeepContractItemItem();
    }

    public class KeepContractItemItem implements AdapterItem<KeepContractVo> {
        LinearLayout   ripple;
        LinearLayout mainLayout;
        TextView     tvYear;
        TextView     tvCompanyName;


        private KeepContractVo mData;
        private int            mPosition;

        @Override
        public int getLayoutResId() {
            return R.layout.item_keep_contract;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            mainLayout = (LinearLayout) root.findViewById(R.id.mainLayout);
            tvYear = (TextView) root.findViewById(R.id.tv_year);
            tvCompanyName = (TextView) root.findViewById(R.id.tv_company_name);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    KeepEditEvent event = new KeepEditEvent();
                    event.setData(mData);
                    event.setTag(KeepEditEvent.class.getName());
                    event.setPosition(mPosition);
                    AppService.getBus().post(event);
                }
            });
        }

        @Override
        public void handleData(KeepContractVo data, int position) {
            mData = data;
            mPosition = position;

            tvCompanyName.setText(StringUtils.nullValue(data.getAgencyInfoVo().getAgencyName()));
            tvYear.setText(StringUtils.nullValue(data.getKeep_year()) + "年");
        }
    }
}
